﻿using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Threading.Tasks;
using PortalWeb.Core.Entity;
using PortalWeb.Core.IDao;

namespace PortalWeb.Dao
{
    public partial class RoleGroupStore: IDisposable
    {
        public IQueryable<RoleGroup> RoleGroups
        {
            get { return Context.Set<RoleGroup>(); }
        }

    

        public new async Task AddAsync(RoleGroup roleGroup)
        {
            if (roleGroup == null)
            {
                throw new ArgumentNullException("roleGroup");
            }
            Context.Set<RoleGroup>().AddOrUpdate(roleGroup);
            await SaveChanges();
        }

        private async Task SaveChanges()
        {
            await Context.SaveChangesAsync();
        }

        public async Task DeleteAsync(RoleGroup function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }
            Context.Set<RoleGroup>().Remove(function);
            await SaveChanges();
        }

        public Task<RoleGroup> FindByIdAsync(int id)
        {
            return Context.Set<RoleGroup>().FirstOrDefaultAsync(p => p.Id == id);
        }

        public async Task UpdateAsync(RoleGroup function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }
            Context.Set<RoleGroup>().AddOrUpdate(function);
            await SaveChanges();
        }

        private bool _disposed;

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !this._disposed)
            {
                this._disposed = true;
            }
        }
    }
}
